FROM python:3.9.5-slim-buster

RUN pip install --upgrade pip -i https://mirror.baidu.com/pypi/simple \
    && pip install paddlehub --upgrade -i https://mirror.baidu.com/pypi/simple \
    && sed -i "s@/deb.debian.org/@/mirrors.aliyun.com/@g" /etc/apt/sources.list \
    && apt-get update 
RUN apt-get     -o Acquire::BrokenProxy="true" \
    -o Acquire::http::No-Cache="true" \ 
    -o Acquire::http::Pipeline-Depth="0" \ 
    install gcc git libgl1-mesa-glx libglib2.0-dev -y \
    && git clone https://gitee.com/paddlepaddle/PaddleOCR.git

WORKDIR /PaddleOCR
ADD requirements.txt requirements.txt

RUN pip install -r requirements.txt -i https://mirror.baidu.com/pypi/simple

RUN mkdir -p /PaddleOCR/inference/ \
    && mkdir -p /PaddleOCR/static/photo/

ADD https://paddleocr.bj.bcebos.com/dygraph_v2.0/ch/ch_ppocr_server_v2.0_det_infer.tar /PaddleOCR/inference/
ADD https://paddleocr.bj.bcebos.com/dygraph_v2.0/ch/ch_ppocr_server_v2.0_rec_infer.tar /PaddleOCR/inference/
ADD https://paddleocr.bj.bcebos.com/dygraph_v2.0/ch/ch_ppocr_mobile_v2.0_cls_infer.tar /PaddleOCR/inference/
ADD config.py config.py
ADD app.py app.py

RUN tar xf /PaddleOCR/inference/ch_ppocr_server_v2.0_det_infer.tar -C /PaddleOCR/inference/ \
    && tar xf /PaddleOCR/inference/ch_ppocr_server_v2.0_rec_infer.tar -C /PaddleOCR/inference/ \
    && tar xf /PaddleOCR/inference/ch_ppocr_mobile_v2.0_cls_infer.tar -C /PaddleOCR/inference \
    && sed -i  '163c\            print(text)' tools/infer/predict_system.py \
    && rm -rf /root/.cache && apt-get autoclean \
    && apt-get --purge autoremove -y git \
    && rm -rf /tmp/* /var/lib/apt/* /var/cache/* /var/log/* \
    && rm -f /PaddleOCR/inference/*.tar

EXPOSE 8000

#CMD ["/bin/bash","-c","hub install deploy/hubserving/ocr_system/ && hub serving start -m ocr_system"]
CMD gunicorn -c config.py app:app
#CMD python app.py

